package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.common.base.service.impl.BaseServiceImpl;
import com.example.common.utils.ApiResult;
import com.example.dao.TSourceMapper;
import com.example.model.entity.SuppliesType;
import com.example.model.entity.TSource;
import com.example.model.query.SuppliesTypeQuery;
import com.example.model.query.TSourceQuery;
import com.example.service.TSourceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 *  Service接口实现类
 *
 * @author Tellsea
 * @Description Created on 2020-12-11
 */
@Service
public class TSourceServiceImpl extends BaseServiceImpl<TSourceMapper, TSource> implements TSourceService {

    @Autowired
    private TSourceMapper sourceMapper;

    @Override
    public ApiResult<TSourceQuery> pageUserVoByQuery(TSourceQuery query) {
        query.setOptimizeCountSql(false);
        Long current = query.getCurrent();
        query.setCurrent(1L);
        QueryWrapper<TSource> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(TSource::getIsValid,1L).orderByDesc(TSource::getCreateDate);
        if(StringUtils.isNotBlank(query.getSourceNum())){
            queryWrapper.like("source_num",query.getSourceNum());
        }
        if(StringUtils.isNotBlank(query.getSourceName())){
            queryWrapper.like("source_name",query.getSourceName());
        }
        Integer total = sourceMapper.selectCount(queryWrapper);
        query.setTotal(total);
        query.setCurrent(current);
        sourceMapper.selectPage(query,queryWrapper);
        return new ApiResult<>(query);
    }
    @Override
    public  ApiResult<List<TSource>> getList(){
        QueryWrapper<TSource> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(TSource::getIsValid,1L);
        List<TSource> sysOrganizationList = sourceMapper.selectList(queryWrapper);
        return new ApiResult<>(sysOrganizationList);
    }
    @Override
    public ApiResult<Boolean> saveT(TSource area){
        area.setCreateDate(LocalDateTime.now());
        sourceMapper.insert(area);
        return new ApiResult<>(Boolean.TRUE);
    }
}

